package com.hex.ds.code.detection.common.util;

import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

@Slf4j
public class DataSourceUtil {

    public static void close(Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception e) {
            log.error("[数据比对组件]- 关闭数据源Connection异常：{}", e.getMessage(), e);
        }
    }

    public static void close(Statement statement) {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (Exception e) {
            log.error("[数据比对组件]- 关闭数据源Statement异常：{}", e.getMessage(), e);
        }
    }

    public static void close(ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (Exception e) {
            log.error("[数据比对组件]- 关闭数据源ResultSet异常：{}", e.getMessage(), e);
        }
    }

    public static void close(Connection connection, Statement statement) {
        close(connection);
        close(statement);
    }

    public static void close(Statement statement, ResultSet resultSet) {
        close(statement);
        close(resultSet);
    }

    public static void close(Connection connection, Statement statement, ResultSet resultSet) {
        close(connection);
        close(statement);
        close(resultSet);
    }

    public static void close(Connection connection, ResultSet resultSet) {
        close(connection);
        close(resultSet);
    }
}
